const app = getApp()
const WXAPI = require("../../../api/newApi")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    assetId:'',
    number:'',
    customerExchangePageList:[],
    information:{},
    imgHttp: app.globalData.imgHttp, //图片前缀
    list:[],
    isCanUse:'',//是否展示立即使用按钮
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      statusHeight: app.gettop.height,
      status: app.gettop.status,
      navHeight:app.gettop.navHeight,
      mobbleBottom: app.mobile.mobbleBottom
    })
    console.log(options)
    this.data.isCanUse = options.iscanuse
    this.data.assetId = options.assetId
    this.data.number = options.num
    this.data.customerExchangePageList = JSON.parse(options.list)
    this.getInfomation()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  getInfomation(){
    wx.showLoading({
      title: '加载中',
    })
     var data = {
      assetId: this.data.assetId,
      number: this.data.number,
      customerExchangePageList:this.data.customerExchangePageList,
    }
    WXAPI.customerExchangePage(data, (res) => {
      const data = res.result
      if (res.code == 200) {
        this.setData({
          information: res.result,
          list: res.result.customerExchangePageList
        })
        wx.hideLoading({})
      }
    })
  },
  getPay(){
    console.log(this.data.information)
    wx.showLoading({
      title: '加载中',
    })
    var data = this.data.information
    WXAPI.customerExchangeAsset(data, (res) => {
      const data = res.result
      if (res.code == 200) {
        let info = JSON.stringify(res.result)
        wx.showToast({
          title: '支付成功',
        })
        setTimeout(()=>{
          wx.navigateTo({
            url: '/userPageA/pages/exchange_success/exchange_success?info=' + info,
          })
        },800)
        wx.hideLoading({})
      }
    })
    
  },
  clickBack(){
    wx.navigateBack({
      delta: 0,
    })
  },
  jump(e){
    console.log(e)
    let id =  e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/userPageB/pages/userStore/integralDetail/integralDetail?id='+id+'&assetType=1&path=index'+'&couponid=' + id + '&iscanuse=' + this.data.isCanUse,
    })
  }
})